package com.xuecheng.content.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.po.TeachplanMedia;
import com.xuecheng.content.service.TeachplanMediaService;
import com.xuecheng.content.service.impl.TeachplanServiceImpl;
import io.swagger.annotations.*;
import org.apache.ibatis.annotations.Delete;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 26455
 * @version 1.0
 * @description TODO
 * @date 2023/2/8 14:30
 */
@Api(value = "课程计划编辑接口", tags = "课程计划编辑接口")
@RestController
@RequestMapping("/teachplan")
public class TeachplanController {

    @Autowired
    private TeachplanServiceImpl teachplanService;

    @Autowired
    TeachplanMediaService teachplanMediaService;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId", name = "课程基础Id值", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId) {
        List<TeachplanDto> teachplayTree = teachplanService.findTeachplayTree(courseId);
        return teachplayTree;
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping
    public void saveTeachplan(@RequestBody TeachplanDto teachplanDto) {
        teachplanService.saveTeachplan(teachplanDto);
    }

    @ApiOperation("课程删除")
    @DeleteMapping("/{id}")
    private void removeTeachplan(@PathVariable Long id) {
        teachplanService.removeTeachplan(id);
    }

    @ApiOperation("章节上移")
    @PostMapping("/moveup/{id}")
    private void moveup(@PathVariable Long id) {
        teachplanService.moveup(id);
    }

    @ApiOperation("章节下移")
    @PostMapping("/movedown/{id}")
    private void movedown(@PathVariable Long id) {
        teachplanService.movedown(id);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/association/media")
    private void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto) {
        teachplanMediaService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "删除课程计划和媒资信息绑定")
    @DeleteMapping("/association/media/{teachplanId}/{mediaId}")
    private void associationMedia(@PathVariable(value = "teachplanId" ,required = true) Long teachplanId,
                                  @PathVariable(value = "mediaId",required = true) String mediaId) {
        LambdaQueryWrapper<TeachplanMedia> queryWrapper =new LambdaQueryWrapper<>();
        queryWrapper.eq(TeachplanMedia::getTeachplanId,teachplanId);
        queryWrapper.eq(TeachplanMedia::getMediaId,mediaId);
        teachplanMediaService.remove(queryWrapper);
    }


}
